/**
 * 
 */
package pt.mleiria.cryptographic.streamcipher;

import java.util.BitSet;

/**
 * @author NB13712
 *
 */
public class A5_1 {
	
	/**
	 * Linear feedback shift registers
	 * The key K is 64 bits (8 bytes). The key is used as the initial	ﬁll	of the three registers				
	 */
	final BitSet x = new BitSet(19);
	final BitSet y = new BitSet(22);
	final BitSet z = new BitSet(23);
	
	/**
	 * 1 char = 2 bytes => key.length = 4 
	 * @param key
	 * @param plainText
	 */
	public A5_1(final String key, final String plainText) throws Exception{
		if(key.length() != 4){
			throw new IllegalArgumentException("key must have a size = 4");
		}
		initialFill(key);
	}
	
	private void initialFill(final String key) throws Exception{
		byte[] keyBytes = key.getBytes("UTF-8");
		
		BitSet bits = new BitSet();
	    
		for (int i=0; i<keyBytes.length*8; i++) {
			
	        if ((keyBytes[keyBytes.length-i/8-1] & (1 << (i%8))) > 0) {
	            bits.set(i);
	        }
	    }
	}
	

}
